#include <cstdio>
#include <queue>
using namespace std;

struct log {
	int p, id, et;
	log(int pi, int ID, int t) {
		p = pi; id = ID; et = t;
	}
	bool operator < (const log &x)const {
		if (this->et + this->p == x.et + x.p) {
			return this->id > x.id;
		}
		return this->et + this->p > x.et + x.p;
	}
};

priority_queue<log> q;

int main() {
	int n, a, b;
	char e;
	scanf("%d", &n);
	while (scanf("Register%c", &e)) {
		scanf("%d %d", &a, &b);
		q.push(log(b, a, 0));
		scanf("\n");
	}
	scanf("#");
	scanf("%d", &n);
	while (n--) {
		log x = q.top();
		q.pop();
		printf("%d\n", x.id);
		q.push(log(x.p, x.id, x.et + x.p));
	}
	return 0;
}
